@model PageVM
@{
    var uw = Model.Temp as UserWriting;
    var tt = JArray.Parse(uw.Spare1);
    ViewData["Title"] = uw.UwTitle;

    bool laud = ViewData["uca1"]?.ToString() == "yes";
    bool mark = ViewData["uca2"]?.ToString() == "yes";

    var avatarUrl = AppTo.GetValue("Common:Gravatar");
}

<input class="nr-hid-write-id" type="hidden" value="@uw.UwId" />
<input class="nr-hid-user-id" type="hidden" value="@uw.Uid" />

@Html.Raw(Netnr.QuoteTo.Html("netnrmd.css"))

<div class="container-fluid px-4">

    <!--标题-->
    <div class="row">
        <div class="col-12 mt-4 mb-2">
            <a class="fs-4 text-break" href="/home/list/@uw.UwId">@uw.UwTitle</a>
            <partial name="_PartialTag" model="@uw.Spare1" />
        </div>
    </div>

    <!--标题信息-->
    <div class="row">
        <div class="col mb-2 opacity-75">
            <a class="me-2 small" href='/user/id/@uw.Uid'>@uw.Spare2</a>
            <small class="me-2 d-none d-sm-inline-block" title="创建于">@VisualFormatService.Duration(uw.UwCreateTime.Value)</small>
            @if (uw.UwCreateTime.Value.Date != uw.UwUpdateTime.Value.Date)
            {
                <small class="me-2 d-none d-sm-inline-block" title="更新于">@VisualFormatService.Duration(uw.UwUpdateTime.Value)</small>
            }
            <small class="me-2" title="阅读量"><sl-icon class="align-middle" name="eye"></sl-icon> @VisualFormatService.Count(uw.UwReadNum.Value)</small>
            <small class="me-2" title="回复数"><sl-icon class="align-middle" name="reply"></sl-icon> @uw.UwReplyNum.Value</small>
        </div>
        <div class="col-auto d-none d-sm-inline">
            <sl-button-group>
                @if (mark)
                {
                    <sl-button title="取消收藏" variant="primary" size="small" class="nr-btn-mark">
                        <sl-icon name="bookmark-plus"></sl-icon>
                    </sl-button>
                }
                else
                {
                    <sl-button title="收藏" outline size="small" class="nr-btn-mark">
                        <sl-icon name="bookmark-plus"></sl-icon>
                    </sl-button>
                }
                <sl-button size="small">@uw.UwMark</sl-button>
            </sl-button-group>
            <sl-button-group>
                @if (laud)
                {
                    <sl-button title="取消点赞" variant="primary" size="small" class="nr-btn-laud">
                        <sl-icon name="hand-thumbs-up"></sl-icon>
                    </sl-button>
                }
                else
                {
                    <sl-button title="点赞" outline size="small" class="nr-btn-laud">
                        <sl-icon name="hand-thumbs-up"></sl-icon>
                    </sl-button>
                }
                <sl-button size="small">@uw.UwLaud</sl-button>
            </sl-button-group>
        </div>
        <div class="col-12"><hr /></div>
    </div>

    <!--内容-->
    <div class="row">
        <div class="col-12">
            @if (uw.UwStatus != 1)
            {
                <h2 class="bg-warning text-white text-center py-3">受 限 制 的 文 章</h2>
            }
        </div>

        <div class="col-12 mb-5">
            <div class="markdown-body">
                @Html.Raw(uw.UwContent)
            </div>
        </div>
    </div>

    <!--回复-->
    @if (Model.Pag.Total > 0)
    {
        var listRp = Model.Rows as List<UserReply>;
        int lv = (Model.Pag.PageNumber - 1) * Model.Pag.PageSize;

        <div class="row">
            <div class="col-12 fs-4">
                <span class="float-end">第 @Model.Pag.PageNumber 页</span>@Model.Pag.Total 个回复
                <hr />
            </div>
        </div>

        @foreach (var item in listRp)
        {
            lv += 1;
            var gra = avatarUrl + CalcTo.MD5(item.UrAnonymousMail ?? "") + "?r=pg";

            <div class="row" id="no_@lv">
                <div class="col-auto">
                    @if (item.Uid == 0)
                    {
                        <img class="rounded" width="40" src="@gra" alt="头像" onerror="this.src = '/favicon.svg'; this.onerror = null;">
                    }
                    else
                    {
                        var avatarPath = "/favicon.svg";
                        if (!string.IsNullOrWhiteSpace(item.Spare2))
                        {
                            avatarPath = CommonService.StaticResourceLink("AvatarPath", item.Spare2);
                        }

                        <img class="rounded" width="40" src="@avatarPath" alt="头像" onerror="this.src = '/favicon.svg'; this.onerror = null;">
                    }
                </div>

                <div class="col" id="r_@item.UrId">
                    @if (item.UrStatus == 1)
                    {
                        if (item.Uid == 0)
                        {
                            <a class="small" href="@item.UrAnonymousLink">@item.UrAnonymousName</a>
                            <span class="badge bg-secondary me-2">Guest</span>
                        }
                        else
                        {
                            <a class="me-2 small" href='/user/id/@item.Uid'>@item.Spare1</a>
                        }
                        <small class="me-2 d-none d-sm-inline-block opacity-75" title="创建于">@VisualFormatService.Duration(item.UrCreateTime.Value)</small>
                        <a href="#no_@lv" class="float-end">#@lv</a>

                        <div class="markdown-body mt-2">@Html.Raw(item.UrContent)</div>
                    }
                    else
                    {
                        <small class="me-2 d-none d-sm-inline-block opacity-75" title="创建于">@VisualFormatService.Duration(item.UrCreateTime.Value)</small>
                        <a href="#no_@lv" class="float-end">#@lv</a>

                        <div class="mt-2">
                            <span class="badge bg-dark">Block</span>
                        </div>
                    }
                </div>

                <div class="col-12">
                    <hr />
                </div>
            </div>
        }

        <partial name="_PartialPaging" />
    }

    @if (ViewContext.HttpContext.User.Identity.IsAuthenticated && !AppTo.GetValue<bool>("ReadOnly"))
    {
        <div class="row my-5">
            <!--回复帖子-->
            <div class="col-md-12">
                <h4>回复<sl-button size="small" class="nr-btn-preview ms-2">预览</sl-button></h4>
                <sl-textarea class="nr-editor mb-3" placeholder="支持 Markdown 语法"></sl-textarea>
                <div class="nr-preview mb-3"></div>
                <sl-button variant="warning" class="nr-btn-reply">回复</sl-button>
            </div>
        </div>
    }

</div>

@Html.Raw(Netnr.QuoteTo.Html("netnrmd.js"))
<script src="/js/home/list.js" asp-append-version="true"></script>